#!/usr/bin/env python
# encoding: utf-8

"""
    项目配置文件config.py
"""

import os

DEBUG = False

basedir = os.path.abspath(os.path.dirname(__file__))

class Config(object):
    DEBUG = False
    TESTING = False
    # 打开跨站请求
    CSRF_ENABLED = True
    SECRET_KEY = 'Sm9obiBTY2hyb20ga2lja3MgYXNz'
    STRIPE_API_KEY = 'SmFjb2IgS2FwbGFuLU1vc3MgaXMgYSBoZXJv'

    API_IGNORE_URLS = [
        "^/api"
    ]

    UPLOAD_IMAGES = {
        'ext':[ 'jpg','gif','bmp','jpeg','png' ],
        'prefix_path':'/static/upload/',
        'prefix_url':'/static/upload/'
    }

    UPLOAD_FILES = {
        'prefix_path':'/static/upload/',
        'prefix_url':'/static/upload/'
    }

class ProductionConfig(Config):
    DEBUG = False
    SERVER_PORT = 80

    APP = {
        'domain':'http://47.96.188.120:6001'
    }

    mysql = {
        # 'DATABASE': 'stock_prod',
        'DATABASE': 'stock_dev',
        'PASSWORD': 'p@ssw0rd123',
        'USER':     'root',
        'HOSTNAME': 'mysql', # docker用法
    }

    SQLALCHEMY_DATABASE_URI='mysql+pymysql://%s:%s@%s/%s'%(mysql['USER'], mysql['PASSWORD'], mysql['HOSTNAME'], mysql['DATABASE'])

class StagingConfig(Config):
    DEVELOPMENT = True
    DEBUG = True


class DevelopmentConfig(Config):
    DEVELOPMENT = True
    DEBUG = True
    SERVER_PORT = 5000

    APP = {
        'domain':'http://192.168.232.137:5000'
    }

    # 默认数据库引擎
    mysql = {
        'DATABASE': 'stock_dev',
        'PASSWORD': 'p@ssw0rd123',
        'USER':     'root',
        'HOSTNAME': '47.96.188.120:6002',
    }
    SQLALCHEMY_DATABASE_URI='mysql+pymysql://%s:%s@%s/%s'%(mysql['USER'], mysql['PASSWORD'], mysql['HOSTNAME'], mysql['DATABASE'])
    #设置这一项是每次请求结束后都会自动提交数据库中的变动
    #  SQLALCHEMY_TRACK_MODIFICATIONS=True

    old_mysql_conf = {
        'DATABASE': 'nrs_stock',
        'PASSWORD': '#Redfalsh192729',
        'USER':     'xiong',
        'HOSTNAME': '47.96.188.120:3306',
    }

    # 配置多个数据库连接
    SQLALCHEMY_BINDS = {
        'old': 'mysql+pymysql://%s:%s@%s/%s'%(old_mysql_conf['USER'], old_mysql_conf['PASSWORD'], old_mysql_conf['HOSTNAME'], old_mysql_conf['DATABASE'])
    }



class TestingConfig(Config):
    TESTING = True

config = {
    'development': DevelopmentConfig,
    'testing': TestingConfig,
    'production': ProductionConfig,
    'default': DevelopmentConfig
}
